package com.common;
import java.io.IOException;
import javax.servlet.*;
import javax.servlet.http.*;
import com.common.GlobalSetting;

public class MyFilter extends HttpServlet implements Filter
{
	 protected FilterConfig filterConfig;
 
	 public void doFilter(final ServletRequest req,final ServletResponse res,FilterChain chain)throws IOException,ServletException
	 {
    		HttpServletRequest hreq = (HttpServletRequest)req;
    		HttpServletResponse hres = (HttpServletResponse)res;
    		String cur=(String)hreq.getSession().getAttribute("uid");
    		String url=GlobalSetting.getProperty("root")+hreq.getRequestURI();
          	if(url.equals(GlobalSetting.getProperty("backend_login_path")) || cur!=null)
		    {
          		chain.doFilter(req,res);
          		return;
		    }
		    else
		    {
		    	//hres.sendRedirect(GlobalSetting.getProperty("backend_login_path"));
		    	hres.setCharacterEncoding("gb2312");
		    	hres.getWriter().write("<script>alert('您可能长时间没有活动，session已过期，请重新登录');parent.location.href='"+GlobalSetting.getProperty("backend_login_path")+"';</script>");
		    }
	 }
	 
	 
  
	  public void destroy()
	  {
		  this.filterConfig=null;
	  }
	  public void init(FilterConfig config)
	  {
		  this.filterConfig=config;
	  }
	  public void setFilterConfig(final FilterConfig filterConfig)
	  {
		  this.filterConfig=filterConfig;
	  }
}
